package com.summer.designMode;

public class SingletonMode {

	private final String name;
	private static boolean init = false;
	
	private SingletonMode(String name){
		this.name = name ;
		System.out.println("SingletonMode init");
	}
	
	public static void init(String name){
		init = true;
		SingletonConfig.name = name;
	}
	
	private static class SingletonConfig{
		public static String name;
	}
	
	public static class Singleton{
		private static final SingletonMode singletonMode = new SingletonMode(SingletonConfig.name);
	}
	
	public static SingletonMode get(){
		if(!init){
			System.out.println("没有初始化");
			return null;
		}
		return Singleton.singletonMode;
	}
	
	public void println(){
		System.out.println(name+"单例开始工作了");
	}
	
	public static void main(String[] args) throws InterruptedException {
		
		System.out.println("开始了");
		
		for(int index=0;index<10;index++)
			System.out.println("在工作了");
		Thread.sleep(1000);
		
		SingletonMode.get();
		SingletonMode.init("summer");
		SingletonMode.get().println();
		SingletonMode.init("summer2");
		SingletonMode.get().println();
	}
}
